<?php

/* ******************************
 *	Request aJax actions
* ******************************
*/

require_once('../../../includes/classes/core.php');
include('../../../includes/classes/log.class.php');
$log 		= new log();
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

$action 	= $_REQUEST['act'];


//task
$id		    		= $_REQUEST['id'];
$incom_id			= $_REQUEST['id1'];
$person_id			= $_REQUEST['person_id'];
$problem_comment	= $_REQUEST['problem_comment'];
$comment 	     	= $_REQUEST['comment1'];
$priority_id 		= $_REQUEST['priority_id'];
$task_status 		= $_REQUEST['task_status'];
$template_id		= $_REQUEST['template_id'];
$person_id			= $_REQUEST['person_id'];
$task_type_id		= $_REQUEST['task_type_id'];
$task_date			= $_REQUEST['task_date'];
$task_status		= $_REQUEST['status'];

$delivery_time_id		= $_REQUEST['delivery_time_id'];
$delivery_time_comment	= $_REQUEST['delivery_time_comment'];
$montage_time_id	    = $_REQUEST['montage_time_id'];
$montage_time_comment	= $_REQUEST['montage_time_comment'];
$consulting_id	        = $_REQUEST['consulting_id'];
$consulting_comment	    = $_REQUEST['consulting_comment'];
$shipping_id		    = $_REQUEST['shipping_id'];
$shipping_comment	    = $_REQUEST['shipping_comment'];
$montage_id	            = $_REQUEST['montage_id'];
$montage_comment	    = $_REQUEST['montage_comment'];
$service_object_id      = $_REQUEST['service_object_id'];
$mom_1                  = $_REQUEST['mom_1'];
$mom_2                  = $_REQUEST['mom_2'];
$mom_3                  = $_REQUEST['mom_3'];
$mom_4                  = $_REQUEST['mom_4'];
$mom_1_comment          = $_REQUEST['mom_1_comment'];
$mom_2_comment          = $_REQUEST['mom_2_comment'];
$mom_3_comment          = $_REQUEST['mom_3_comment'];
$mom_4_comment          = $_REQUEST['mom_4_comment'];
$gad_1                  = $_REQUEST['gad_1'];
$gad_2                  = $_REQUEST['gad_2'];
$gad_3                  = $_REQUEST['gad_3'];
$gad_4                  = $_REQUEST['gad_4'];
$gad_5                  = $_REQUEST['gad_5'];
$gad_1_comment          = $_REQUEST['gad_1_comment'];
$gad_2_comment          = $_REQUEST['gad_2_comment'];
$gad_3_comment          = $_REQUEST['gad_3_comment'];
$gad_4_comment          = $_REQUEST['gad_4_comment'];
$gad_5_comment          = $_REQUEST['gad_5_comment'];
$sag_1                  = $_REQUEST['sag_1'];
$sag_2                  = $_REQUEST['sag_2'];
$sag_3                  = $_REQUEST['sag_3'];
$sag_1_comment          = $_REQUEST['sag_1_comment'];
$sag_2_comment          = $_REQUEST['sag_2_comment'];
$sag_3_comment          = $_REQUEST['sag_3_comment'];

// file
$rand_file			= $_REQUEST['rand_file'];
$file				= $_REQUEST['file_name'];


switch ($action) {
	case 'get_add_page':
		$number		= $_REQUEST['number'];
		$page		= GetPage($res='', $number);
		$data		= array('page'	=> $page);

		break;
	case 'disable':
		$incom_id				= $_REQUEST['id'];
		mysql_query("	UPDATE `task`
						SET `actived`=0
						WHERE `id`=$incom_id ");
		break;	
	case 'get_edit_page':
		$page		= GetPage(Gettask($id));

		$data		= array('page'	=> $page);

		break;
	case 'get_list' :
		$count 		= $_REQUEST['count'];
		$hidden 	= $_REQUEST['hidden'];
		$user_id	= $_SESSION['USERID'];
		$user_id	= $_SESSION['USERID'];
		$user		= $_SESSION['USERID'];
		$group		= checkgroup($user);
		
		$filter = '';
		if ($group != 1) {
			$res_row = mysql_fetch_assoc(mysql_query("SELECT 	users.person_id
					FROM 	`users`
					WHERE 	`users`.`id` = $user_id"));
		
			$filter = 'AND task.responsible_user_id ='. $res_row[person_id];
		}
		mysql_query("SET @i = 0;");
  		$rResult = mysql_query("SELECT		`task`.id,
											`task`.id,
  											`persons`.`name`,
  											task_type.`name`,
											template.`name`,
											priority.`name`,
											task.`comment`
							FROM 			`task`
							
							LEFT JOIN		task_type ON task.task_type_id = task_type.id
							LEFT JOIN		template ON task.template_id = template.id
							LEFT JOIN		priority ON task.priority_id = priority.id
							JOIN 		persons ON task.responsible_user_id=persons.id
							WHERE 		task.actived=1 and task.task_type_id= 1 AND task.`status`=2 $filter
									
	  			");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
				if($i == ($count - 1)){
					$row[] = '<input type="checkbox" name="check_' . $aRow[$hidden] . '" class="check" value="' . $aRow[$hidden] . '" />';
				}
			}
			$data['aaData'][] = $row;
		}

		break;
	case 'save_outgoing2':
		
	
			savetask($id, $problem_comment, $delivery_time_id, $delivery_time_comment, $montage_time_id, $montage_time_comment, $consulting_id, $consulting_comment, $shipping_id, $shipping_comment, $montage_id, $montage_comment,$service_object_id, $mom_1, $mom_1_comment,$mom_2,$mom_2_comment,$mom_3,$mom_3_comment,$mom_4,$mom_4_comment,$sag_1,$sag_1_comment,$sag_2,$sag_2_comment,$sag_3,$sag_3_comment,$gad_1,$gad_1_comment,$gad_2,$gad_2_comment,$gad_3,$gad_3_comment,$gad_4,$gad_4_comment,$gad_5,$gad_5_comment);	
		
		break;
		case 'done_outgoing2':
		
			$user_id		= $_SESSION['USERID'];
		
			Savetask1($problem_comment, $delivery_time_id, $delivery_time_comment, $montage_time_id, $montage_time_comment, $consulting_id, $consulting_comment, $shipping_id, $shipping_comment, $montage_id, $montage_comment,$service_object_id, $mom_1, $mom_1_comment,$mom_2,$mom_2_comment,$mom_3,$mom_3_comment,$mom_4,$mom_4_comment,$sag_1,$sag_1_comment,$sag_2,$sag_2_comment,$sag_3,$sag_3_comment,$gad_1,$gad_1_comment,$gad_2,$gad_2_comment,$gad_3,$gad_3_comment,$gad_4,$gad_4_comment,$gad_5,$gad_5_comment);
			break;
		case 'get_add_info':
			 
			$pin	=	$_REQUEST['pin'];
			$data 	= 	array('info' => get_addition_all_info($pin));
			 
			break;
		case 'get_responsible_person_add_page':
			$page 		= GetResoniblePersonPage();
			$data		= array('page'	=> $page);
		
			break;
		
		case 'change_responsible_person':
			$letters 			= json_decode( '['.$_REQUEST['lt'].']' );
			$responsible_person = $_REQUEST['rp'];
		
			ChangeResponsiblePerson($letters, $responsible_person);
		
			break;
		case 'get_add_info1':
		
			$pin_n	=	$_REQUEST['pin_n'];
			$data 	= 	array('info1' => get_addition_all_info1($pin_n));
			//get_addition_all_info1
		
			break;
			case 'sub_produqtion':
					
				$brand_id = $_REQUEST['brand_id'];
				$data  =  array('cat'=> Get_production_brand($brand_id, ''));
					
				break;
			case 'sub_produqtion1':
					
				$prod_id = $_REQUEST['prod_id'];
				$categ_id = $_REQUEST['categ_id'];
				$data  =  array('cat'=>  Get_production($prod_id, $categ_id, ''));
					
				break;
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);


/* ******************************
 *	Request Functions
* ******************************
*/
function checkgroup($user){
	$res = mysql_fetch_assoc(mysql_query("
			SELECT users.group_id
			FROM    users
			WHERE  users.id = $user
			"));
	return $res['group_id'];

}
      
function savetask($id, $problem_comment, $delivery_time_id, $delivery_time_comment, $montage_time_id, $montage_time_comment, $consulting_id, $consulting_comment, $shipping_id, $shipping_comment, $montage_id, $montage_comment,$service_object_id, $mom_1, $mom_1_comment,$mom_2,$mom_2_comment,$mom_3,$mom_3_comment,$mom_4,$mom_4_comment,$sag_1,$sag_1_comment,$sag_2,$sag_2_comment,$sag_3,$sag_3_comment,$gad_1,$gad_1_comment,$gad_2,$gad_2_comment,$gad_3,$gad_3_comment,$gad_4,$gad_4_comment,$gad_5,$gad_5_comment)
{
//echo $id.'-'.$problem_comment;
	//GLOBAL $log;
	//$log->setUpdateLogAfter('task', $id);
	$c_date		= date('Y-m-d H:i:s');
	$user  = $_SESSION['USERID'];
	mysql_query("UPDATE `task` SET 
						
								`user_id`='$user', 
								`date`='$c_date', 
								`problem_comment`='$problem_comment',
								`delivery_time_id`='$delivery_time_id',
                                `delivery_time_comment`='$delivery_time_comment',
                                `montage_time_id`='$montage_time_id',
                                `montage_time_comment`='$montage_time_comment',
                                `consulting_id`='$consulting_id',
                                `consulting_comment`='$consulting_comment',
                                `shipping_id`='$shipping_id',
                                `shipping_comment`='$shipping_comment',
                                `montage_id`='$montage_id',
                                `montage_comment`='$montage_comment',
                                `service_object_id`='$service_object_id',
                                `mom_1`='$mom_1',
                                `mom_1_comment`='$mom_1_comment',
                                `mom_2`='$mom_2',
                                `mom_2_comment`='$mom_2_comment',
                                `mom_3`='$mom_3',
                                `mom_3_comment`='$mom_3_comment',
                                `mom_4`='$mom_4',
                                `mom_4_comment`='$mom_4_comment',
                                `sag_1`='$sag_1',
                                `sag_1_comment`='$sag_1_comment',
                                `sag_2`='$sag_2',
                                `sag_2_comment`='$sag_2_comment',
                                `sag_3`='$sag_3',
                                `sag_3_comment`='$sag_3_comment',
                                `gad_1`='$gad_1',
                                `gad_1_comment`='$gad_1_comment',
                                `gad_2`='$gad_2',
                                `gad_2_comment`='$gad_2_comment',
                                `gad_3`='$gad_3',
                                `gad_3_comment`='$gad_3_comment',
                                `gad_4`='$gad_4',
                                `gad_4_comment`='$gad_4_comment',
                                `gad_5`='$gad_5',
                                `gad_5_comment`='$gad_5_comment'
					WHERE		`id`='$id'
					");
	//$log->setInsertLog('task',$id);

}
function Savetask1($problem_comment, $delivery_time_id, $delivery_time_comment, $montage_time_id, $montage_time_comment, $consulting_id, $consulting_comment, $shipping_id, $shipping_comment, $montage_id, $montage_comment,$service_object_id, $mom_1, $mom_1_comment,$mom_2,$mom_2_comment,$mom_3,$mom_3_comment,$mom_4,$mom_4_comment,$sag_1,$sag_1_comment,$sag_2,$sag_2_comment,$sag_3,$sag_3_comment,$gad_1,$gad_1_comment,$gad_2,$gad_2_comment,$gad_3,$gad_3_comment,$gad_4,$gad_4_comment,$gad_5,$gad_5_comment)
{
	//GLOBAL $log;
	//$log->setUpdateLogAfter('task', $id);
	$hidden_task_id1	= $_REQUEST['hidden_task_id1'];
	$c_date				= date('Y-m-d H:i:s');
	$user  				= $_SESSION['USERID'];
	mysql_query("UPDATE `task` SET
								`user_id`			='$user',
								`problem_comment`	='$problem_comment',
								`status`	='3',
								`delivery_time_id`='$delivery_time_id',
                                `delivery_time_comment`='$delivery_time_comment',
                                `montage_time_id`='$montage_time_id',
                                `montage_time_comment`='$montage_time_comment',
                                `consulting_id`='$consulting_id',
                                `consulting_comment`='$consulting_comment',
                                `shipping_id`='$shipping_id',
                                `shipping_comment`='$shipping_comment',
                                `montage_id`='$montage_id',
                                `montage_comment`='$montage_comment',
                                `service_object_id`='$service_object_id',
                                `mom_1`='$mom_1',
                                `mom_1_comment`='$mom_1_comment',
                                `mom_2`='$mom_2',
                                `mom_2_comment`='$mom_2_comment',
                                `mom_3`='$mom_3',
                                `mom_3_comment`='$mom_3_comment',
                                `mom_4`='$mom_4',
                                `mom_4_comment`='$mom_4_comment',
                                `sag_1`='$sag_1',
                                `sag_1_comment`='$sag_1_comment',
                                `sag_2`='$sag_2',
                                `sag_2_comment`='$sag_2_comment',
                                `sag_3`='$sag_3',
                                `sag_3_comment`='$sag_3_comment',
                                `gad_1`='$gad_1',
                                `gad_1_comment`='$gad_1_comment',
                                `gad_2`='$gad_2',
                                `gad_2_comment`='$gad_2_comment',
                                `gad_3`='$gad_3',
                                `gad_3_comment`='$gad_3_comment',
                                `gad_4`='$gad_4',
                                `gad_4_comment`='$gad_4_comment',
                                `gad_5`='$gad_5',
                                `gad_5_comment`='$gad_5_comment'
								WHERE 	`id`		='$hidden_task_id1'
								");
	//$log->setInsertLog('task',$id);
}

function Getobject($object_id)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `name`
					FROM 	`object`
					WHERE 	actived=1");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $object_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Get_source($source_id)

{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `surce`
						WHERE actived=1 ");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $source_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getcategory($category_id)

{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `info_category`
						WHERE actived=1 && parent_id=0 ");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function Getcategory1($category_id)
{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
			FROM `info_category`
			WHERE actived=1 && parent_id=$category_id");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;

}
function Getcategory1_edit($category_id)
{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
			FROM `info_category`
			WHERE actived=1 && id=$category_id");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;

}

function Get_production($prod_id, $categ_id, $edit)
{
	$data = '';
	if($edit == ''){
		$req = mysql_query("SELECT DISTINCT production.`name` as id,
				production.`name`
				FROM    production
				WHERE   actived = 1 AND production.production_category='$categ_id' AND production.brand='$prod_id'");
	}else {
		$req = mysql_query("SELECT DISTINCT production.`name` as id,
				production.`name`
				FROM    production
				WHERE   actived = 1 AND production.`name`='$prod_id' ");
	}
	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $prod_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}


function Get_production_category($production_category_id)
{
	$data = '';
	$req = mysql_query("SELECT DISTINCT production.production_category as id,
								production.`production_category`
						FROM    production
						WHERE   actived = 1 ");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $production_category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['production_category'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['production_category'] . '</option>';
		}
	}

	return $data;
}

function Get_production_brand($brand_id, $edit)
{
	$data = '';
	if($edit == ''){
		$req = mysql_query("SELECT DISTINCT production.brand as id,
				production.`brand`
				FROM    production
				WHERE   actived = 1 AND production.production_category='$brand_id' ");
	}else {
		$req = mysql_query("SELECT DISTINCT production.brand as id,
				production.`brand`
				FROM    production
				WHERE   actived = 1 AND production.brand='$brand_id' ");
	}

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $brand_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['brand'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['brand'] . '</option>';
		}
	}

	return $data;
}


function Getpriority($priority_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `priority`
						WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $priority_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function Get_reaction($reaction_id)
{
	$data = '';
	$req = mysql_query("SELECT reaction.id,
								reaction.`name`
						FROM    reaction ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $reaction_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}


function Get_task_type($task_type_id)
{
	$data = '';
	$req = mysql_query("SELECT 	task_type.id,
								task_type.`name`
						FROM	task_type
						WHERE 	task_type.actived=1");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $task_type_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getpersons($persons_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
							FROM `persons`
							WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $persons_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getstatus($task_status)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `call_status`
						FROM `status`
						WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $task_status){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['call_status'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['call_status'] . '</option>';
		}
	}

	return $data;
}

function Getservicesstatus($id)
{
    $data = '';
    $req = mysql_query("SELECT  `id`,
                                `name`
						FROM    `services_status`
						WHERE   `actived` = 1 ");


    $data .= '<option value="0" selected="selected">----</option>';
    while( $res = mysql_fetch_assoc($req)){
        if($res['id'] == $id){
            $data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
        } else {
            $data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
        }
    }

    return $data;
}

function Get_template($template)
{
	$data = '';
	$req = mysql_query("SELECT 	template.id,
								template.`name`
						FROM    template
						WHERE 	template.actived=1");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $template){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getservicesobject($id)
{
    $data = '';
    $req = mysql_query("SELECT  `id`,
                                `name`
						FROM    `object`
						WHERE   `actived` = 1 ");


    $data .= '<option value="0" selected="selected">----</option>';
    while( $res = mysql_fetch_assoc($req)){
        if($res['id'] == $id){
            $data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
        } else {
            $data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
        }
    }

    return $data;
}


function get_addition_all_info1($pin_n)
{
	$data = '';
	//echo $pin_n; return 0;
	$req=mysql_query("		SELECT 	realizations.id as c_id,
			realizations.CustomerAddress,
			realizations.`CustomerName` AS client_name,
			realizations.CustomerAddress,
			realizations.CustomerPhone,
			SUM(`realizations`.`Sum`)AS jami,

			CASE
			WHEN  SUM(`realizations`.`Sum`)>5000
			AND
			SUM(`realizations`.`Sum`)<=7000
			THEN 'VIP-Gold'
			WHEN  SUM(`realizations`.`Sum`)  >7000
			AND
			SUM(`realizations`.`Sum`)<=10000
			THEN 'VIP-Platinium'
			WHEN SUM(`realizations`.`Sum`) >10000
			THEN 'VIP-Briliant'
			WHEN SUM(`realizations`.`Sum`)<=5000 and COUNT(realizations.CustomerName)>5
			THEN 'ლოიალური'
			END AS `status`
			FROM 	realizations
			JOIN nomenclature ON realizations.id=nomenclature.realizations_id

			WHERE realizations.CustomerID=$pin_n
			LIMIT 1");

	$res = mysql_fetch_assoc($req);
		
	$data .= '<fieldset >
			<legend>ძირითადი ინფორმაცია</legend>
		<table style="height: 152px;">
			<tr>
				<td style="width: 180px; color: #3C7FB1;">ტელეფონი</td>
				<td style="width: 180px; color: #3C7FB1;">პირადი ნომერი</td>
			</tr>
			<tr>
				<td>'.$res['CustomerPhone'].'</td>
					<td style="width: 180px;">
				<input type="text" id="personal_pin" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $pin_n . '" />
				</td>
			</tr>
			<tr>
				<td style="width: 180px; color: #3C7FB1;">კონტრაგენტი</td>
				<td style="width: 180px; color: #3C7FB1;">ელ-ფოსტა</td>
			</tr>
			<tr >
				<td style="width: 180px;">'.$res['client_name'].'</td>
					<td style="width: 180px;">'.$res[''].'</td>
			</tr>
			<tr>
			<td td style="width: 180px; color: #3C7FB1;">მისამართი</td>
				<td td style="width: 180px; color: #3C7FB1;">სტატუსი</td>
			</tr>
			<tr>
				<td style="width: 180px;">'.$res['CustomerAddress'].'</td>
				<td td style="width: 180px;">'.$res['status'].'</td>
			</tr>

			</table>
			</fieldset>


				<fieldset>
				<legend>შენაძენები</legend>
				<div id="dt_example" class="inner-table">
		        <div style="width:349px;" id="container" >
		            <div id="dynamic">
		            	<div id="button_area">
		            	</div>
		                <table class="" id="examplee_3" style="width: 100%;">
		                    <thead>
								<tr  id="datatable_header">

		                           <th style="display:none">ID</th>
									<th style="width:15%;">თარიღი</th>
									<th style=" width:15%;">საწყობი</th>
									<th style="width:15%;">პროდუქტი</th>
									<th style="width:15%;">თანხა</th>
								</tr>
							</thead>
							<thead>
								<tr class="search_header">
									<th class="colum_hidden">
                            			<input type="text" name="search_id" value="ფილტრი" class="search_init" style="width: 66px"/>
                            		</th>
									<th>
										<input style="width:94px;" type="text" name="search_overhead" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input style="width:100px;" type="text" name="search_partner" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input style="width:66px;" type="text" name="search_overhead" value="ფილტრი" class="search_init" />
									</th>
			
			
								</tr>
							</thead>
		                </table>
		            </div>
		            <div class="spacer">
		            </div>
		        </div>
				</fieldset>
							<!-- ID -->
		 		<input type="hidden" id="c_id3" value="' . $res['c_id'] . '" />
												';
	//$data[c_id][]=$req[c_id];
	return $data;
}

function Gettask($id)
{
	$res = mysql_fetch_assoc(mysql_query("SELECT 	task.id,
													task.sales_id,
													incomming_call.date AS incom_date,
													DATE_FORMAT(incomming_call.`date`,'%Y-%m-%d') AS record_date,
													incomming_call.phone AS incom_phone,
													incomming_call.first_name AS first_name,
													incomming_call.information_category_id AS category_id,
													incomming_call.information_sub_category_id AS category_parent_id,
													incomming_call.production_id AS production_brand_id,	
													incomming_call.production_category_id AS production_category_id,
													incomming_call.production_brand_id AS production_id,
													incomming_call.redirect AS redirect,
													incomming_call.reaction_id AS reaction_id,
													incomming_call.connect AS connect,
													incomming_call.content AS content,
													incomming_call.production_type AS production_type,
													incomming_call.requester AS requester,
													incomming_call.sale_date,
													incomming_call.source_id,
													incomming_call.pid AS personal_pin,
													IF(task.incomming_call_id=0,realizations.`CustomerID`,cl.`CustomerID`) AS personal_pin,
													IF(task.incomming_call_id='',realizations.`CustomerID`,cl.`CustomerID`) AS personal_pin,
													task.responsible_user_id AS person_id,
													task.client_id,
													task.task_type_id AS task_type_id,
													task.template_id AS template_id,
													task.priority_id AS priority_id,
													task.status AS status,
													task.`comment` AS `comment1`,
													task.delivery_time_id,
													task.delivery_time_comment,
	                                                task.montage_time_id,
													task.montage_time_comment,
                                            	    task.consulting_id,
                                            	    task.shipping_id,
                                            	    task.montage_id,
	                                                task.service_object_id,
	                                                task.consulting_comment,
                                            	    task.shipping_comment,
                                            	    task.montage_comment,
													task.problem_comment AS problem_comment,
													task.client_actived_id,		
	                                                task.`mom_1`,
                                                    task.`mom_1_comment`,
                                                    task.`mom_2`,
                                                    task.`mom_2_comment`,
                                                    task.`mom_3`,
                                                    task.`mom_3_comment`,
                                                    task.`mom_4`,
                                                    task.`mom_4_comment`,
                                                    task.`sag_1`,
                                                    task.`sag_1_comment`,
                                                    task.`sag_2`,
                                                    task.`sag_2_comment`,
                                                    task.`sag_3`,
                                                    task.`sag_3_comment`,
                                                    task.`gad_1`,
                                                    task.`gad_1_comment`,
                                                    task.`gad_2`,
                                                    task.`gad_2_comment`,
                                                    task.`gad_3`,
                                                    task.`gad_3_comment`,
                                                    task.`gad_4`,
                                                    task.`gad_4_comment`,
                                                    task.`gad_5`,
                                                    task.`gad_5_comment`,			
													realizations.id AS nom_id,
													realizations.StoreHouse,
													realizations.WaybillRecieveDate,
													realizations.Subdivision,
													realizations.Date,
													realizations.WaybillActivationDate,
													IF(realizations.instalation_date='0000-00-00 00:00:00','',realizations.instalation_date) AS instalation_date,
													realizations.WaybillStatus,
													realizations.CustomerID,
													realizations.CustomerAddress,
													realizations.CustomerName,
													realizations.CustomerPhone,
													realizations.born_date AS born_date,
													realizations.CustomerAddress AS Juristic_address,
													realizations.phone2,
													realizations.phone3,
													realizations.justin_adress,
													realizations.fact_adress,
													realizations.mail,
													realizations.sity,
													realizations.fact_sity,
													realizations.fac_postal_cide,
													realizations.fostal_code,
													realizations.`comment`,
													CASE WHEN SUM(`nomenclature`.`Sum`)>=5000 
														AND
														SUM(`nomenclature`.`Sum`)<7000
														THEN 'VIP Gold'
													 WHEN SUM(`nomenclature`.`Sum`)>=7000 
														AND
														SUM(`nomenclature`.`Sum`)<10000
														THEN 'VIP Platinium'
													WHEN SUM(`nomenclature`.`Sum`)>10000 
														THEN 'VIP Briliant'
													WHEN SUM(`nomenclature`.`Sum`)<5000 
														THEN 'ლოიალური'
												END AS `cl_status`,

													'რედაქტირება' AS `edit`
													FROM 	task
										
											LEFT JOIN 	incomming_call 		ON incomming_call.id=task.incomming_call_id
											LEFT JOIN 	realizations ON task.client_id = realizations.id
											LEFT JOIN 	realizations AS cl ON cl.id=incomming_call.client_id
											LEFT JOIN   nomenclature ON realizations.id=nomenclature.realizations_id
											left JOIN 	surce 		ON incomming_call.source_id=surce.id
											WHERE 	task.id=$id
			" ));
		
	return $res;
}


function GetPage($res='', $number, $pin)
{
	
	
	if($res['connect']==1){
		$connect0="checked";
	}else{
		$connect0="";
	}
	
	if($res['requester']==1){
		$requester0="checked";
		$requester1="";
	}elseif ($res['requester']==2){
		$requester1="checked";
		$requester0="";
	}
	if($res['production_type']==1){
		$production_type0="checked";
		$production_type1="";
	}elseif ($res['production_type']==2){
		$production_type1="checked";
		$production_type0="";
	}
	if($res['client_id'] != '' && $res['client_actived_id'] == 0){
		$hide2='';
	}else{
		$hide2="style='display:none;'";
	}
	if($res['client_actived_id'] == 0){
		$hide2='';
		$hide4="style='display:none;'";
	}else{
		$hide2='display:none;';
		$hide4='';
	}
	if ($res['incom_phone'] =='')
	{
$hide="style='display:none;'";
$hide1="";
	} else 
	{
		
$hide1="style='display:none;'";
$hide2='display:none;';
$hide="";
	}	
$num = 0;
	if($res[phone]==""){
	$num=$number;
	}else{
		$num=$res[phone];
		}
		$data  .= '
		<!-- jQuery Dialog -->
    <div id="add-edit-goods-form" title="საქონელი">
    	<!-- aJax -->
	</div>
	<div id="dialog-form">
				<div  style="float: left; width: 803px;">
				<fieldset '.$hide4.' style="width:780px; float:left;">
				    	<table width="100%" class="dialog-form-table">
							<tr>
								<td>სტატუსი</td>
								<td>'.$res['cl_status'].'</td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td>კონტრაგენტი</td>
								<td>
									<input type="text" id="client_name" class="idle" onblur="this.className=\'idle\'"  value="' . $res['CustomerName']. '"  />
								</td>
								<td>მობილური 1</td>
								<td>
									<input type="text" id="client_mobile" class="idle" onblur="this.className=\'idle\'"  value="' . $res['CustomerPhone']. '"  />
								</td>

							</tr>
							<tr>
								<td>იურ. სტატუსი</td>
								<td>
									<select id="legal_status_id" class="idls object">'.$res['legal_status_id'].'</select>
								</td>
								<td>მობილური 2</td>
								<td>
									<input type="text" id="client_mobile1" class="idle" onblur="this.className=\'idle\'"  value="' . $res['phone2']. '"  />
								</td>

							</tr>
							<tr>
								<td>პირადი ნომერი</td>
								<td>
									<input type="text" id="client_pin" class="idle" onblur="this.className=\'idle\'"  value="' . $res['CustomerID']. '"  />
								</td>
								<td>ტელეფონი</td>
								<td>
									<input type="text" id="client_phone2" class="idle" onblur="this.className=\'idle\'"  value="' . $res['phone3']. '"  />
								</td>
							</tr>
							<tr>
								<td>დაბ. თარიღი</td>
								<td>
									<input type="text" id="born_date" class="idle" onblur="this.className=\'idle\'"  value="' . $res['born_date']. '"  />
								</td>
								<td>ელ-ფოსტა</td>
								<td>
									<input type="text" id="client_mail" class="idle" onblur="this.className=\'idle\'"  value="' . $res['mail']. '"  />
								</td>
							</tr>

						</tr>
						</table>
					</fieldset>
						<fieldset '.$hide4.' style="width:780px; float:left;">
						<legend>მოკლე შინაარსი</legend>
				    	<table width="100%" class="dialog-form-table">
							<tr>
							<td colspan="6">
								<textarea  style="width: 627px; height: 35px; resize: none;" id="client_comment" class="idle" name="content" cols="300" rows="2">' . $res['comment'] . '</textarea>
							</td>
						</table>
						</fieldset>
					<fieldset '.$hide4.'
							 style="width:780px; float:left; margin-bottom: 6px;">
						<legend>მისამართი</legend>
				    	<table width="100%" class="dialog-form-table">
							<tr>
								<td style="font-weight:bold;">იურიდიული</td>
								<td></td>
								<td style="font-weight:bold;">ფაქტიური</td>
								<td></td>
							</tr>
							<tr>
								<td>მისამართი</td>
								<td>
									<input type="text" id="Juristic_address" class="idle" onblur="this.className=\'idle\'"  value="' . $res['CustomerAddress']. '"  />
								</td>
								<td>მისამართი</td>
								<td>
									<input type="text" id="physical_address" class="idle" onblur="this.className=\'idle\'"  value="' . $res['fact_adress']. '"  />
								</td>
							</tr>
							<tr>
								<td>ქალაქი</td>
								<td>
									<input type="text" id="Juristic_city" class="idle" onblur="this.className=\'idle\'"  value="' . $res['sity']. '"  />
								</td>
								<td>ქალაქი</td>
								<td>
									<input type="text" id="physical_city" class="idle" onblur="this.className=\'idle\'"  value="' . $res['fact_sity']. '"  />
								</td>
							</tr>
							<tr>
								<td>საფოსტო კოდი</td>
								<td>
									<input type="text" id="Juristic_postal_code" class="idle" onblur="this.className=\'idle\'"  value="' . $res['fostal_code']. '"  />
								</td>
								<td>საფოსტო კოდი</td>
								<td>
									<input type="text" id="physical_postal_code" class="idle" onblur="this.className=\'idle\'"  value="' . $res['fac_postal_cide']. '"  />
								</td>
							</tr>
						</table>
						</fieldset>	
				<fieldset >
					
			    	<fieldset  style="width:367px; float:left; '.$hide2.'" >
						<table width="100%" class="dialog-form-table">
							<tr>
								<td>ზედნადების #</td>
								<td>
									<input type="text" id="id" class="idle" onblur="this.className=\'idle\'" value="' . $res['nom_id']. '"disabled="disabled"/>
								</td>
							</tr>
							<tr>
								<td>ქვე-განყოფილება</td>
								<td>
									<input type="text" id="Subdivision" class="idle" onblur="this.className=\'idle\'" value="' . $res['Subdivision']. '"disabled="disabled"/>
								</td>
							</tr>
							<tr>
								<td>საწყობი</td>
								<td>
									<input type="text" id="CustomerName" class="idle" onblur="this.className=\'idle\'" value="' . $res['StoreHouse']. '"disabled="disabled"/>
								</td>
							</tr>	
							<tr>
								<td></td>
								<td>
									
								</td>
							</tr>					
						</table>
					</fieldset>
					<fieldset style="width:354px; float:left; margin-left: 10px; '.$hide2.'">
				    	<table width="100%" class="dialog-form-table">
							<tr>
								<td>შეძენის თარიღი</td>
								<td>
									<input type="text" id="Date" class="idle" onblur="this.className=\'idle\'"  value="' . $res['WaybillActivationDate']. '"disabled="disabled"/>
								</td>
							</tr>
							<tr>
								<td>მიტანის თარიღი</td>
								<td>
									<input type="text" id="WaybillRecieveDate" class="idle" onblur="this.className=\'idle\'" value="' . $res['WaybillRecieveDate']. '"disabled="disabled"/>
								</td>
							</tr>
							<tr>
								<td>მონტაჟის თარიღი</td>
								<td>
									<input type="text" id="mont_date" class="idle" onblur="this.className=\'idle\'"  value="' . $res['instalation_date']. '"/>
								</td>
							</tr>
							<tr>
								<td>სტატუსი</td>
								<td>
									<input type="text" id="WaybillStatus" class="idle" onblur="this.className=\'idle\'" value="' . $res['WaybillStatus']. '"disabled="disabled"/>
								</td>
							</tr>						
						</table>
					</fieldset>						
											';
												
		$data  .= '
		   
				<fieldset '.$hide.' >

			    	<table  width="100%" class="dialog-form-table">
						<tr>
							<td style="width: 180px;"><label for="">მომართვა №</label></td>
							<td style="width: 180px;"><label for="">თარიღი</label></td>
							<td style="width: 180px;"><label for="phone" >ტელეფონი</label></td>
							<td></td>
							<td><label for="person_name">აბონენტის სახელი</label></td>
						</tr>
						<tr>
							<td style="width: 180px;">
								<input type="text" id="task_id" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField user_id\'" value="' . $res['id']. '" disabled="disabled" />
							</td>
							<td style="width: 180px;">
								<input type="text" id="incom_date" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField date\'" value="' .  $res['incom_date']. '" disabled="disabled" />
							</td>
							<td style="width: 180px;">
								<input type="text" id="incom_phone" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['incom_phone'] . '" '.$hide.'disabled="disabled" />
										</td>
							<td style="width: 69px;">
								<button class="calls"'.$hide.'>ნომრები</button>
							</td>
							<td style="width: 69px;">
								<input type="text" id="first_name" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['first_name'] . '" '.$hide.' />
								</td>
						</tr>
					</table>
										
		</fieldset>								';

		$data  .= '

		<fieldset '.$hide.'  style="width:142px; float:left;height: 59px;">
			    	<legend>მომართვის ავტორი</legend>
					<table id="additional" class="dialog-form-table" width="100px">						
						<tr>
							<td style="width: 100px;"><input style="float:left;" type="radio" name = "5" value="1" '.$requester0.' ><span style="margin-top:9px; display:block;">ფიზიკური</span></td>
						</tr>
						<tr>
							<td style="width: 100px;"><input style="float:left;" type="radio" name = "5" value="2" '.$requester1.' ><span style="margin-top:9px; display:block;">იურიდიული</span></td>
						</tr>
					</table>
				</fieldset>
				<fieldset '.$hide.'  style="width:142px; float:left;margin-left: 2px;">
			    	<legend>ინფ. წყარო</legend>
					<table id="additional" class="dialog-form-table" width="100px">						
						<tr>
							<td style="width: 300px;"><select id="source_id" class="idls object"disabled="disabled">'.Get_source($res['source_id']).'</select></td>
						</tr>
					</table>
				</fieldset>
			<fieldset '.$hide.'  style="width:399px; float:left; margin-left: 3px;">
			    	<legend>ინფორმაციის კატეგორია</legend>
					<table id="additional" class="dialog-form-table" width="230px">						
						<tr>
							<td style="width: 300px;"><select style="margin-left: 25px;" id="category_parent_id" class="idls object"disabled="disabled">'.   Getcategory($res['category_parent_id']).'</select></td>
							<td style="width: 300px;"><select style="margin-left: 15px;" id="category_id" class="idls object"disabled="disabled">'. Getcategory1_edit($res['category_id']).'</select></td>
						</tr>
					</table>
				</fieldset>
				<fieldset '.$hide.' style="width:755px; float:left;">
			    	<legend>პროდუქტი</legend>
					<table id="additional" class="dialog-form-table" width="230px">
						<tr>
							<td style="width: 250px;"><input style="float:left;" name = "10" type="radio" value="1" '.$production_type0.' disabled="disabled"><span style="margin-top:9px; display:block;">შეძენილი</span></td>
							<td style="width: 250px;"><input style="float:left; margin-left: 20px;" type="radio" name = "10" value="2"'.$production_type1.' disabled="disabled"><span style="margin-top:9px; display:block;"">საინტერესო</span></td>
							<td style="width: 250px;"></td>
							<td style="width: 250px;"></td>
						</tr>
						<tr>
							<td style="width: 300px;"><label for="d_number">კატეგორია</label></td>
							<td style="width: 300px;"><label style="margin-left: 15px;" for="d_number">ბრენდი</label></td>
							<td style="width: 250px;"><label style="margin-left: 25px;" for="d_number">პროდუქტი</label></td>
							<td style="width: 250px;"><label style="margin-left: 25px;" for="d_number">შეძენის თარიღი</label></td>
							
						</tr>
						<tr>
							<td style="width: 300px;"><select id="production_category_id" class="idls object" disabled="disabled">'.Get_production_category($res['production_category_id']).'</select></td>
							<td style="width: 300px;"><select style="margin-left: 15px;" id="production_brand_id" class="idls object" disabled="disabled">'.Get_production_brand($res['production_brand_id'], $res['edit']).'</select></td>
							<td style="width: 250px;"><select style="margin-left: 25px;" id="production_id" class="idls object" disabled="disabled">'.Get_production($res['production_id'], '', $res['edit']).'</select></td>
							<td style="width: 250px;"><input style="margin-left: 25px;" type="text"  id="sale_date" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['sale_date'] . '"disabled="disabled" /></td>
						</tr>
		</table>
				</fieldset>
				<fieldset '.$hide.' style="width:755px; float:left;">
			    	<legend>გადამისამართება</legend>
					<table id="additional" class="dialog-form-table" width="230px">
						<tr>
							<td style="width: 300px;"><label for="d_number">ქვე-განყოფილება</label></td>
							<td style="width: 300px;"><label style="margin-left: 35px;" for="d_number">კავშირი</label></td>
						</tr>
						<tr>
							<td style="width: 250px;"><select style=" width: 450px;" id="redirect" class="idls object" disabled="disabled">'. Getobject($res['redirect']).'</select></td>
							<td style="width: 250px;"><input name="check_" style="margin-left: 35px;" type="checkbox" value="1"disabled="disabled"'.$connect0.'></td>
						</tr>
					</table>
				</fieldset>
				<fieldset '.$hide.' style="width:160px; float:left;">
			    	<legend>რეაგირება</legend>
					<table id="additional" class="dialog-form-table" width="150px">
						<tr>
							<td style="width: 150px;"><select id="reaction_id" class="idls object" disabled="disabled">'. Get_reaction($res['reaction_id']).'</select></td>
						</tr>
						</table>
						</fieldset>
				<fieldset '.$hide.' style="width:557px; float:left; margin-left: 10px;">
			    	<legend>შინაარსი</legend>
					<table id="additional" class="dialog-form-table" width="150px">
						<tr>
							<td><textarea  style="width: 550px; resize: none;" id="content" class="idle" name="content" cols="300" disabled="disabled">' . $res['content'] . '</textarea></td>
						</tr>
					</table>
					</fieldset>
				';

		$data  .= '
		 
		<fieldset style="width: 754px;">
		<legend>დავალების ფორმირება</legend>

			    	<table class="dialog-form-table">
						<tr>
							<td style="width: 180px;"><label for="d_number">დავალების ტიპი</label></td>
							<td style="width: 180px;"><label for="d_number">სცენარი</label></td>
							<td style="width: 180px;"><label for="d_number">პრიორიტეტი</label></td>
						</tr>
			    		<tr>
							<td style="width: 180px;"><select id="task_type_id" class="idls object">'.Get_task_type($res['task_type_id']).'</select></td>
							<td style="width: 180px;"><select id="template_id" class="idls object">'. Get_template($res['template_id']).'</select></td>
							<td style="width: 180px;"><select id="priority_id" class="idls object">'.Getpriority($res['priority_id']).'</select></td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="d_number">პასუხისმგებელი პირი</label></td>
							<td '.$hide1.' style="width: 180px;"><label for="d_number">სტატუსი</label></td>
							<td style="width: 180px;"></td>
						</tr>
			    		<tr>
							<td style="width: 180px;"><select style="width: 164px;" id="person_id" class="idls object">'.Getpersons($res['person_id']).'</select></td>
							<td '.$hide1.' style="width: 180px;"><select style="width: 166px;" id="status" class="idls object">'.Getstatus($res['status']).'</select></td>
							<td style="width: 180px;"></td>
						</tr>
						<tr>
							<td style="width: 150px;"><label for="content">კომენტარი</label></td>
							<td style="width: 150px;"><label for="content"></label></td>
							<td style="width: 150px;"><label for="content"></label></td>
						</tr>
						<tr>
							<td colspan="6">
								<textarea  style="width: 747px; resize: none;" id="comment1" class="idle" name="comment1" cols="300" rows="2">' . $res['comment1'] . '</textarea>
							</td>
						</tr>
						<!--tr>
							<td style="width: 150px;"><label for="content">პრობლემის გადაწყვეტა</label></td>
							<td style="width: 150px;"><label for="content"></label></td>
							<td style="width: 150px;"><label for="content"></label></td>
						</tr>
						<tr>
							<td colspan="6">
								<textarea  style="width: 747px; resize: none;" id="problem_comment" class="idle" name="problem_comment" cols="300" rows="2">' . $res['problem_comment'] . '</textarea>
							</td>
						</tr-->
					</table>
					</fieldset>
					<fieldset style="width: 754px; margin-top:5px;">
					<fieldset id="momsaxureba" class="">
			    	    <legend>მომსახურება</legend>
        				<table class="dialog-form-table">
            		    		<tr>
            						<td style="width:415px;">მაღაზიაში შესვლის თანავე მიაქცია თუ არა კონსულტანტმა ყურადღება</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="mom_1" class="idls object">
								        '.GetQuest($res['mom_1']).'
            						    </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="mom_1_comment" class="idle">'.$res['mom_1_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">რამდენად გულისხმიერი იყო კონსულტანტი</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="mom_2" class="idls object">
            					        '.GetVote($res['mom_2']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="mom_2_comment" class="idle">'.$res['mom_2_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">რამდენად კარგად ახსნა პროდუქტის ტექნიკური მახასიათებლები და ფუნქციები</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="mom_3" class="idls object">
            					        '.GetVote($res['mom_3']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="mom_3_comment" class="idle">'.$res['mom_3_comment'].'</textarea></td>
							    </tr>
            			</table> 
            					        
            		    <table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">გაქვთ თუ არა სურვილი კიდევ შეიძინოთ სმაილში სასურველი ტექნიკა</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="mom_4" class="idls object">
            					        '.GetQuest($res['mom_4']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="mom_4_comment" class="idle">'.$res['mom_4_comment'].'</textarea></td>
							    </tr>
            			</table>   
        			</fieldset>
            	       
            		<fieldset id="gadazidva" class="">
			    	    <legend>გადაზიდვა</legend>
        				<table class="dialog-form-table">
            		    		<tr>
            						<td style="width:415px;">მოიტანა თუ არა გადამზიდმა ჯგუფმა პროდუქტი დროულად</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="gad_1" class="idls object">
            					        '.GetVote($res['gad_1']).'
            						    </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="gad_1_comment" class="idle">'.$res['gad_1_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">იყო თუ არა მომსახურე პერსონალი თავაზიანი</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="gad_2" class="idls object">
            					        '.GetVote($res['gad_2']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="gad_2_comment" class="idle">'.$res['gad_2_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">შეამოწმეთ თუ არა ნივთი ვიზუალურად ჩაბარებისას</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="gad_3" class="idls object">
            					        '.GetVote($res['gad_3']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="gad_3_comment" class="idle">'.$res['gad_3_comment'].'</textarea></td>
							    </tr>
            			</table> 
            					        
            		    <table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">შეავსო თუ არა გადამზიდმა ჯგუფმა მწარმოებლის საგარანტიო დალონი და დაარტყა ბეჭედი</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="gad_4" class="idls object">
            					        '.GetQuest($res['gad_4']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="gad_4_comment" class="idle">'.$res['gad_4_comment'].'</textarea></td>
							    </tr>
            			</table>   
            		</fieldset>
            					        
            		<fieldset id="sagarantio" class="">
			    	    <legend>საგარანტიო</legend>
        				<table class="dialog-form-table">
            		    		<tr>
            						<td style="width:415px;">რამდენად სწრაფად მოხდა რეაგირება</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="sag_1" class="idls object">
            					        '.GetVote($res['sag_1']).'
            						    </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="sag_1_comment" class="idle">'.$res['sag_1_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">რამდენად დროულად მოგვარდა პრობლემა</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="sag_2" class="idls object">
            					        '.GetVote($res['sag_2']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="sag_2_comment" class="idle">'.$res['sag_2_comment'].'</textarea></td>
							    </tr>
            			</table>
        				
        				<table class="dialog-form-table" class="">
            		    		<tr>
            						<td style="width:415px;">რამდენად კეთილგანწყობილი იყო სერვისის თანამშრომელი</td>
            					    <td style="width: 55px;"><select style="width: 55px; margin-right:5px;" id="sag_3" class="idls object">
            					        '.GetVote($res['sag_3']).'
            					        </select></td>
            					    <td><textarea  style="width: 327px; max-width:327px; height:60px;" id="sag_3_comment" class="idle">'.$res['sag_3_comment'].'</textarea></td>
							    </tr>
            			</table> 
        			</fieldset>
				    </fieldset>
							</div>
			
				</fieldset>
			<div '.$hide1.' style=" margin-left:809px;  width: 375px;">
				 <fieldset>
					<legend>კონტრაგენტი</legend>
					<table style="height: 163px;">						
						<tr>
							<td style="width: 180px; color: #3C7FB1;">ტელეფონი</td>
							<td style="width: 180px; color: #3C7FB1;">პირადი ნომერი</td>
						</tr>
						<tr>
							<td style="width: 180px; color: #3C7FB1;">'.$res['CustomerPhone'].'</td>
							<td style="width: 180px; color: #3C7FB1;">'.$res['CustomerID'].'</td>	
						</tr>
						<tr>
							<td style="width: 180px; color: #3C7FB1;">სახელი და გვარი</td>
							<td style="width: 180px; color: #3C7FB1;">ელ-ფოსტა</td>
						</tr>
						<tr >
							<td style="width: 180px;">'.$res['CustomerName'].'</td>
							<td style="width: 180px;">'.$res['CustomerAddress'].'</td>			
						</tr>
						<tr>
							<td td style="width: 180px; color: #3C7FB1;">მისამართი</td>
							<td td style="width: 180px; color: #3C7FB1;">სტატუსი</td>
						</tr>
						<tr>
							<td style="width: 180px;">'.$res['CustomerAddress'].'</td>
							<td td style="width: 180px;">'.$res['cl_status'].'</td>
						</tr>
					</table>
				</fieldset>
				<div id="additional_info">
	  		</div>
			</div>
			<div '.$hide1.' style="float: right;  width: 376px;">
				 <fieldset>
				<legend>შენაძენები</legend>
				<div id="dt_example" class="inner-table">
		        <div style="width:349px;" id="container" >        	
		            <div id="dynamic">
		            	<div id="button_area">
		            	</div>
		                <table class="" id="examplee_5" style="width: 100%;">
		                    <thead>
								<tr  id="datatable_header">
										
		                           <th style="display:none">ID</th>
									<th style="width:15%;">თარიღი</th>
									<th style=" width:15%;">საწყობი</th>
									<th style="width:55%;">პროდუქტი</th>
									<th style="width:15%;">თანხა</th>
								</tr>
							</thead>
							<thead>
								<tr class="search_header">
									<th class="colum_hidden">
                            			<input type="text" name="search_id" value="ფილტრი" class="search_init" style="width: 56px"/>
                            		</th>
									<th>
										<input style="width:94px;" type="text" name="search_overhead" value="ფილტრი" class="search_init" style="width: 63px"/>
									</th>
									<th>
										<input style="width:100px;" type="text" name="search_partner" value="ფილტრი" class="search_init" style="width: 114px"/>
									</th>
									<th>
										<input style="width:66px;" type="text" name="search_overhead" value="ფილტრი" class="search_init" style="width: 70px"/>
									</th>
									
									
								</tr>
							</thead>
		                </table>
		            </div>
		            <div class="spacer">
		            </div>
		        </div>
				</fieldset>
					</div>		
			<div '.$hide.' style="float: right;  width: 376px;">';
					if ($res['incomming_call_id']!='null'){
							
						$data .= get_addition_all_info1($res['personal_pin']);
					}
				$data .= GetRecordingsSection($res);
				
				$data .= '</div>';
			$data .= '
    </table>
		<input type="hidden" id="hidden_task_id1" value="'.$res['id'].'"/>
		<input type="hidden" id="hhhhh_id" value="'.$res[nom_id].'"/> 
		</div>
    </div>';
	return $data;
}
function GetRecordingsSection($res)
{
	if ($res[incom_phone]==''){
		//$data .= '<td colspan="2" style="height: 20px; text-align: center;">ჩანაწერები ვერ მოიძებნა</td>';
	}else{
		$req = mysql_query("SELECT  TIME(`calldate`) AS 'time',
				CONCAT(DATE_FORMAT(calldate, '%Y/%m/%d/'),`recordingfile`) AS `recordingfile`
				FROM     `cdr`
				WHERE     (`dst` = '2555655' && `recordingfile` != '' && DATE(`calldate`) = '$res[record_date]' && `src` LIKE '%$res[incom_phone]%')
				OR      (`dst` LIKE '%$res[incom_phone]%' && `recordingfile` != '' && DATE(`calldate`) = '$res[record_date]');");
	}
	$data .= '
        <fieldset style="margin-top: 10px; width: 353px; float: right;">
            <legend>ჩანაწერები</legend>

            <table style="width: 65%; border: solid 1px #85b1de; margin:auto;">
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <th style="padding-left: 10px;">დრო</th>
                    <th  style="border: solid 1px #85b1de; padding-left: 10px;">ჩანაწერი</th>
                </tr>';
	if (mysql_num_rows($req) == 0){
		$data .= '<td colspan="2" style="height: 20px; text-align: center;">ჩანაწერები ვერ მოიძებნა</td>';
	}

	while( $res2 = mysql_fetch_assoc($req)){
		$src = str_replace(".wav","",$res2[recordingfile]);
	
		$data .= '
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <td>' . $res2[time] . '</td>
                    <td><button class="download" str="' . $src. '">მოსმენა</button></td>
                </tr>';
	}

	$data .= '
            </table>
        </fieldset>';

	return $data;
}
function GetQuest($id){
    if($id == 0){
        $data = '
                <option value="0" selected="selected">--</option>
		        <option value="1" >კი</option>
			    <option value="2" >არა</option>';
    }elseif ($id == 1){
        $data = '
                <option value="0" >--</option>
		        <option value="1" selected="selected">კი</option>
			    <option value="2" >არა</option>';
    }elseif ($id == 2){
        $data = '
                <option value="0" >--</option>
		        <option value="1" >კი</option>
			    <option value="2" selected="selected">არა</option>';
    }
    return $data;
}

function GetVote($id){
    if($id == 0){
        $data = '
                <option value="0" selected="selected">--</option>
                <option value="1" >კი</option>
                <option value="2" >არა</option>
                ';
    }elseif($id == 1){
        $data = '
                <option value="0" >--</option>
                <option value="1" selected="selected">კი</option>
                <option value="2" >არა</option>
                ';
    }elseif($id == 2){
        $data = '
                <option value="0" >--</option>
                <option value="1" >კი</option>
                <option value="2" selected="selected">არა</option>
                ';
    }elseif($id == 3){
        $data = '
                <option value="0" >--</option>
                <option value="1" >კი</option>
                <option value="2" >არა</option>
                ';
    }elseif($id == 4){
        $data = '
                <option value="0" >--</option>
                <option value="1" >კი</option>
                <option value="2" >არა</option>
                ';
    }
    return $data;
}
?>
